home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / circuits / irsim-ca.2 / irsim-ca / irsim-cap-9.2 / src / ana11 / deltaT.c < prev    next >
C/C++ Source or Header  |  1993-01-15  |  5KB  |  254 lines

  1. /*
  2.  *     ********************************************************************* 
  3.  *     * Copyright (C) 1988, 1990 Stanford University.                     * 
  4.  *     * Permission to use, copy, modify, and distribute this              * 
  5.  *     * software and its documentation for any purpose and without        * 
  6.  *     * fee is hereby granted, provided that the above copyright          * 
  7.  *     * notice appear in all copies.  Stanford University                 * 
  8.  *     * makes no representations about the suitability of this            * 
  9.  *     * software for any purpose.  It is provided "as is" without         * 
  10.  *     * express or implied warranty.  Export of this software outside     * 
  11.  *     * of the United States of America may require an export license.    * 
  12.  *     *********************************************************************
  13.  */
  14.  
  15. #include "ana.h"
  16. #include "ana_glob.h"
  17. #include "graphics.h"
  18.  
  19.  
  20. private TimeType FindPreviousEdge( t, tm, edgeH )
  21.   Trptr              t;
  22.   register TimeType  tm;
  23.   hptr               *edgeH;
  24.   {
  25.     register hptr      h;
  26.     register int       val;
  27.     register TimeType  edgeT;
  28.  
  29.     edgeT = tims.start;
  30.     *edgeH = NULL;
  31.     if( IsVector( t ) )
  32.       {
  33.     register int  i;
  34.  
  35.     for( i = t->n.vec->nbits - 1; i >= 0; i-- )
  36.       {
  37.         h = t->cache[i].wind;
  38.         val = h->val;
  39.         while( h->time <= tm )
  40.           {
  41.         if( val != h->val )
  42.           {
  43.             val = h->val;
  44.             if( h->time > edgeT )
  45.             edgeT = h->time;
  46.           }
  47.         NEXTH( h, h );
  48.           }
  49.       }
  50.       }
  51.     else
  52.       {
  53.     h = t->cache[0].wind;
  54.     val = h->val;
  55.     while( h->time <= tm )
  56.       {
  57.         if( val != h->val )
  58.           {
  59.         val = h->val;
  60.         edgeT = h->time;
  61.         *edgeH = h;
  62.           }
  63.         NEXTH( h, h );
  64.       }
  65.       }
  66.     return( edgeT );
  67.   }
  68.  
  69.  
  70. private TimeType FindNextEdge( t, tm, edgeH )
  71.   Trptr              t;
  72.   register TimeType  tm;
  73.   hptr               *edgeH;
  74.   {
  75.     register hptr      h, p;
  76.     register int       val;
  77.     register TimeType  edgeT, endT;
  78.  
  79.     endT = edgeT = min( tims.end, tims.last );
  80.     *edgeH = NULL;
  81.     if( IsVector( t ) )
  82.       {
  83.     register int  i;
  84.  
  85.     for( i = t->n.vec->nbits - 1; i >= 0; i-- )
  86.       {
  87.         p = h = t->cache[i].wind;
  88.         while( h->time <= tm )
  89.           {
  90.         p = h;
  91.         NEXTH( h, h );
  92.           }
  93.         val = p->val;
  94.         while( h->time <= endT )
  95.           {
  96.         if( val != h->val )
  97.           {
  98.             if( h->time < edgeT )
  99.             edgeT = h->time;
  100.             break;
  101.           }
  102.         NEXTH( h, h );
  103.           }
  104.       }
  105.       }
  106.     else
  107.       {
  108.     p = h = t->cache[0].wind;
  109.     while( h->time <= tm )
  110.       {
  111.         p = h;
  112.         NEXTH( h, h );
  113.       }
  114.     val = p->val;
  115.     while( h->time <= endT )
  116.       {
  117.         if( val != h->val )
  118.           {
  119.         edgeT = h->time;
  120.         *edgeH = h;
  121.         break;
  122.           }
  123.         NEXTH( h, h );
  124.       }
  125.       }
  126.     return( edgeT );
  127.   }
  128.  
  129.  
  130. private void WaitForRelease()
  131.   {
  132.     XEvent  e;
  133.     
  134.     GrabMouse( window, ButtonPressMask | ButtonReleaseMask, None );
  135.  
  136.     do
  137.     XNextEvent( display, &e );
  138.     while( e.type != ButtonRelease );
  139.  
  140.     XUngrabPointer( display, CurrentTime );
  141.   }
  142.  
  143.  
  144. private    Trptr       t1;
  145. private Coord       x1;
  146. private TimeType    time1;
  147. private void        SetEdge2();
  148.  
  149.  
  150. private void Terminate( cancel )
  151.   int  cancel;
  152.   {
  153.     if( cancel )
  154.     PRINT( "(canceled: click on a trace)" );
  155.     SendEventTo( NULL );
  156.     XDefineCursor( display, window, cursors.deflt );
  157.     RestoreScroll();
  158.   }
  159.  
  160.  
  161. private void SetEdge1( ev )
  162.   XButtonEvent  *ev;
  163.   {
  164.     TimeType  tm;
  165.     hptr      h;
  166.  
  167.     if( ev == NULL )
  168.       {
  169.     Terminate( FALSE );
  170.     return;
  171.       }
  172.  
  173.     if( ev->type != ButtonPress )
  174.     return;
  175.     
  176.     t1 = GetYTrace( ev->y );
  177.     tm = XToTime( ev->x );
  178.     if( t1 == NULL or tm < 0 )
  179.       {
  180.     Terminate( TRUE );
  181.     return;
  182.       }
  183.     time1 = FindPreviousEdge( t1, tm, &h );
  184.     x1 = TimeToX( time1 );
  185.     PRINTF( "%.1f", d2ns( time1 ) );
  186.     if( h != NULL )
  187.     PRINTF( " [%.1f, %.1f]", d2ns( h->t.r.delay ), d2ns( h->t.r.rtime ) );
  188.  
  189.     FillAREA( window, x1 - 1, t1->top, 3, t1->bot - t1->top + 1, gcs.hilite );
  190.     WaitForRelease();
  191.     FillAREA( window, x1 - 1, t1->top, 3, t1->bot - t1->top + 1, gcs.unhilite);
  192.  
  193.     PRINT( " | t2 = " );
  194.     XDefineCursor( display, window, cursors.right );
  195.     SendEventTo( SetEdge2 );
  196.   }
  197.  
  198.  
  199. private void SetEdge2( ev )
  200.   XKeyEvent  *ev;
  201.   {
  202.     TimeType  time2, diff;
  203.     Trptr     t2;
  204.     Coord     x2, y1, y2;
  205.     hptr      h;
  206.  
  207.     if( ev == NULL )
  208.       {
  209.     Terminate( FALSE );
  210.     return;
  211.       }
  212.  
  213.     if( ev->type != ButtonPress )
  214.     return;
  215.  
  216.     t2 = GetYTrace( ev->y );
  217.     time2 = XToTime( ev->x );
  218.     if( t2 == NULL or time2 < 0 )
  219.       {
  220.     Terminate( TRUE );
  221.     return;
  222.       }
  223.     time2 = FindNextEdge( t2, time2, &h );
  224.     x2 = TimeToX( time2 );
  225.  
  226.     if( time2 < time1 )
  227.     diff = time1 - time2;
  228.     else
  229.     diff = time2 - time1;
  230.  
  231.     PRINTF( "%.1f", d2ns( time2 ) );
  232.     if( h != NULL )
  233.     PRINTF( " [%.1f, %.1f]", d2ns( h->t.r.delay ), d2ns( h->t.r.rtime ) );
  234.     PRINTF( " | diff = %.1f", d2ns( diff ) );
  235.  
  236.     y1 = (t1->top + t1->bot) / 2;
  237.     y2 = (t2->top + t2->bot) / 2;
  238.     XDrawLine( display, window, gcs.hilite, x1, y1, x2, y2 );
  239.     WaitForRelease();
  240.     XDrawLine( display, window, gcs.unhilite, x1, y1, x2, y2 );
  241.  
  242.     Terminate( FALSE );
  243.   }
  244.  
  245.  
  246. public void DeltaT( s )
  247.   char *s;            /* menu string => ignore it */
  248.   {
  249.     PRINT( "\nt1 = " );
  250.     SendEventTo( SetEdge1 );
  251.     XDefineCursor( display, window, cursors.left );
  252.     DisableScroll();
  253.   }
  254.